﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Kmust.App_Data.KmustDataTableAdapters;
using Kmust.App_Data;
using System.Data;
using Kmust.Commom;

namespace Kmust.KmustControl
{
    /// <summary>
    /// RoomControl.xaml 的交互逻辑
    /// </summary>
    public partial class RoomControl : UserControl
    {
        private string sourceCode;

        public delegate void ChangeCodeHandler(object send, object e);

        public RoomControl()
        {
            InitializeComponent();
            initDate();
        }

        Kmust.App_Data.KmustData.RoomDataTable xsd = new App_Data.KmustData.RoomDataTable();
     //   KmustPager Page = new KmustPager();
        private void initDate()
        {
            using (RoomTableAdapter xs = new RoomTableAdapter())
            {
                xsd = xs.GetData();
            }
        }

        private string setsource;

        public string setSource
        {
            get { return setsource; }
            set {
                setsource = value;
                upDate(value);   
            }
        }

        //自定义属性
        public static readonly DependencyProperty setSourceProperty = DependencyProperty.Register("setSource", typeof(string), typeof(OrderRoomWindow), null);

        private void Romm_Grid_Loaded(object sender, RoutedEventArgs e)
        {
            //using(RoomTableAdapter room=new RoomTableAdapter())
            //{
            //    Romm_Grid.ItemsSource = room.GetData();
            //}
        }

        //UI数据更新
        public void upDate(string value)
        {
            //page.NMax=xsd.TableName("XS").
          //  Page.NMax = xsd.Count(row => row.ZZJGM.Equals(value));
            // Page.PageCurrent = 1;
          //  AllCountLabel.Content = "总记录数：" + Page.NMax.ToString();
         //   CountLabel.Content = "总页数: " + Page.PageCount;
         //   CurrentLabel.Content = "当前页:" + (Page.PageCurrent + 1).ToString();
            Romm_Grid.ItemsSource=xsd.Where(row=>row.OrganizationCode.Equals(setSource));
            Romm_Grid.UpdateLayout();
           
        }

        public event ChangeCodeHandler ChangeCode;
        //自定义转换日期格式需要的类

        public class DateFormatters : IValueConverter
        {

            public object Convert(object value, Type targetType, object parameter,

            System.Globalization.CultureInfo culture)
            {

                //下面可以自行把value格式化成你想要的格式

                //以下是我把传进来的值按照日期类型格式化的

                value = DateTime.Parse(value.ToString()).ToString("yyyy年MM月dd日HH:mm:ss");

                return value.ToString();

            }

            public object ConvertBack(object value, Type targetType,

            object parameter, System.Globalization.CultureInfo culture)
            {

                //throw new NotImplementedException();

                return null;

            }

        }

        private void CheckBox_Click_1(object sender, RoutedEventArgs e)
        {
            sourceCode = (e.OriginalSource as CheckBox).Tag.ToString();
            if (sourceCode != null)
            {
                ChangeCode(this,(object)sourceCode);
            }
        }

        
    }
}
